<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>for_each_point</title>
<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../../index.html" title="Chapter 1. Geometry">
<link rel="up" href="../for_each.html" title="for_each">
<link rel="prev" href="../for_each.html" title="for_each">
<link rel="next" href="for_each_segment.html" title="for_each_segment">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../for_each.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../for_each.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="for_each_segment.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="geometry.reference.algorithms.for_each.for_each_point"></a><a class="link" href="for_each_point.html" title="for_each_point">for_each_point</a>
</h5></div></div></div>
<p>
            <a class="indexterm" name="idm46632"></a>
Applies function <span class="bold"><strong>f</strong></span> to each point.
          </p>
<h6>
<a name="geometry.reference.algorithms.for_each.for_each_point.h0"></a>
            <span class="phrase"><a name="geometry.reference.algorithms.for_each.for_each_point.description"></a></span><a class="link" href="for_each_point.html#geometry.reference.algorithms.for_each.for_each_point.description">Description</a>
          </h6>
<p>
            Applies a function <span class="bold"><strong>f</strong></span> (functor, having
            operator() defined) to each point making up the geometry
          </p>
<h6>
<a name="geometry.reference.algorithms.for_each.for_each_point.h1"></a>
            <span class="phrase"><a name="geometry.reference.algorithms.for_each.for_each_point.synopsis"></a></span><a class="link" href="for_each_point.html#geometry.reference.algorithms.for_each.for_each_point.synopsis">Synopsis</a>
          </h6>
<p>
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Geometry</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Functor</span><span class="special">&gt;</span>
<span class="identifier">Functor</span> <span class="identifier">for_each_point</span><span class="special">(</span><span class="identifier">Geometry</span> <span class="special">&amp;</span> <span class="identifier">geometry</span><span class="special">,</span> <span class="identifier">Functor</span> <span class="identifier">f</span><span class="special">)</span></pre>
<p>
          </p>
<h6>
<a name="geometry.reference.algorithms.for_each.for_each_point.h2"></a>
            <span class="phrase"><a name="geometry.reference.algorithms.for_each.for_each_point.parameters"></a></span><a class="link" href="for_each_point.html#geometry.reference.algorithms.for_each.for_each_point.parameters">Parameters</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Type
                    </p>
                  </th>
<th>
                    <p>
                      Concept
                    </p>
                  </th>
<th>
                    <p>
                      Name
                    </p>
                  </th>
<th>
                    <p>
                      Description
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
                      Geometry &amp;
                    </p>
                  </td>
<td>
                    <p>
                      Any type fulfilling a Geometry Concept
                    </p>
                  </td>
<td>
                    <p>
                      geometry
                    </p>
                  </td>
<td>
                    <p>
                      A model of the specified concept
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      Functor
                    </p>
                  </td>
<td>
                    <p>
                      Function or class with operator()
                    </p>
                  </td>
<td>
                    <p>
                      f
                    </p>
                  </td>
<td>
                    <p>
                      Unary function, taking a point as argument
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
<h6>
<a name="geometry.reference.algorithms.for_each.for_each_point.h3"></a>
            <span class="phrase"><a name="geometry.reference.algorithms.for_each.for_each_point.header"></a></span><a class="link" href="for_each_point.html#geometry.reference.algorithms.for_each.for_each_point.header">Header</a>
          </h6>
<p>
            Either
          </p>
<p>
            <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
          </p>
<p>
            Or
          </p>
<p>
            <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">algorithms</span><span class="special">/</span><span class="identifier">for_each</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
          </p>
<h6>
<a name="geometry.reference.algorithms.for_each.for_each_point.h4"></a>
            <span class="phrase"><a name="geometry.reference.algorithms.for_each.for_each_point.conformance"></a></span><a class="link" href="for_each_point.html#geometry.reference.algorithms.for_each.for_each_point.conformance">Conformance</a>
          </h6>
<p>
            The function for_each_point is not defined by OGC.
          </p>
<p>
            The function for_each_point conforms to the std::for_each function of
            the C++ std-library.
          </p>
<h6>
<a name="geometry.reference.algorithms.for_each.for_each_point.h5"></a>
            <span class="phrase"><a name="geometry.reference.algorithms.for_each.for_each_point.example"></a></span><a class="link" href="for_each_point.html#geometry.reference.algorithms.for_each.for_each_point.example">Example</a>
          </h6>
<p>
            Convenient usage of for_each_point, rounding all points of a geometry
          </p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>

<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">point_xy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">polygon</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>



<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Point</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">round_coordinates</span>
<span class="special">{</span>
<span class="keyword">private</span> <span class="special">:</span>
    <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">coordinate_type</span><span class="special">&lt;</span><span class="identifier">Point</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">coordinate_type</span><span class="special">;</span>
    <span class="identifier">coordinate_type</span> <span class="identifier">factor</span><span class="special">;</span>

    <span class="keyword">inline</span> <span class="identifier">coordinate_type</span> <span class="identifier">round</span><span class="special">(</span><span class="identifier">coordinate_type</span> <span class="identifier">value</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">floor</span><span class="special">(</span><span class="number">0.5</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">value</span> <span class="special">/</span> <span class="identifier">factor</span><span class="special">))</span> <span class="special">*</span> <span class="identifier">factor</span><span class="special">;</span>
    <span class="special">}</span>

<span class="keyword">public</span> <span class="special">:</span>
    <span class="identifier">round_coordinates</span><span class="special">(</span><span class="identifier">coordinate_type</span> <span class="identifier">f</span><span class="special">)</span>
        <span class="special">:</span> <span class="identifier">factor</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
    <span class="special">{}</span>

    <span class="keyword">inline</span> <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">Point</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">get</span><span class="special">;</span>
        <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">set</span><span class="special">;</span>
        <span class="identifier">set</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;(</span><span class="identifier">p</span><span class="special">,</span> <span class="identifier">round</span><span class="special">(</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;(</span><span class="identifier">p</span><span class="special">)));</span>
        <span class="identifier">set</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;(</span><span class="identifier">p</span><span class="special">,</span> <span class="identifier">round</span><span class="special">(</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;(</span><span class="identifier">p</span><span class="special">)));</span>
    <span class="special">}</span>
<span class="special">};</span>


<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">d2</span><span class="special">::</span><span class="identifier">point_xy</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">point</span><span class="special">;</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">polygon</span><span class="special">&lt;</span><span class="identifier">point</span><span class="special">&gt;</span> <span class="identifier">poly</span><span class="special">;</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">read_wkt</span><span class="special">(</span><span class="string">"POLYGON((0 0,1.123 9.987,8.876 2.234,0 0),(3.345 4.456,7.654 8.765,9.123 5.432,3.345 4.456))"</span><span class="special">,</span> <span class="identifier">poly</span><span class="special">);</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">for_each_point</span><span class="special">(</span><span class="identifier">poly</span><span class="special">,</span> <span class="identifier">round_coordinates</span><span class="special">&lt;</span><span class="identifier">point</span><span class="special">&gt;(</span><span class="number">0.1</span><span class="special">));</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Rounded: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">wkt</span><span class="special">(</span><span class="identifier">poly</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
          </p>
<p>
            Output:
          </p>
<pre class="programlisting">Rounded: POLYGON((0 0,1.1 10,8.9 2.2,0 0),(3.3 4.5,7.7 8.8,9.1 5.4,3.3 4.5))
</pre>
<p>
            Sample using for_each_point, using a function to list coordinates
          </p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>

<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">point_xy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">polygon</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>


<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Point</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">list_coordinates</span><span class="special">(</span><span class="identifier">Point</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">get</span><span class="special">;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"x = "</span> <span class="special">&lt;&lt;</span> <span class="identifier">get</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;(</span><span class="identifier">p</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="string">" y = "</span> <span class="special">&lt;&lt;</span> <span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;(</span><span class="identifier">p</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="special">}</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">d2</span><span class="special">::</span><span class="identifier">point_xy</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">point</span><span class="special">;</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">polygon</span><span class="special">&lt;</span><span class="identifier">point</span><span class="special">&gt;</span> <span class="identifier">poly</span><span class="special">;</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">read_wkt</span><span class="special">(</span><span class="string">"POLYGON((0 0,0 4,4 0,0 0))"</span><span class="special">,</span> <span class="identifier">poly</span><span class="special">);</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">for_each_point</span><span class="special">(</span><span class="identifier">poly</span><span class="special">,</span> <span class="identifier">list_coordinates</span><span class="special">&lt;</span><span class="identifier">point</span><span class="special">&gt;);</span>
    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
          </p>
<p>
            Output:
          </p>
<pre class="programlisting">x = 0 y = 0
x = 0 y = 4
x = 4 y = 0
x = 0 y = 0
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2009-2021 Barend Gehrels,
      Bruno Lalande, Mateusz Loskot, Adam Wulkiewicz, Oracle and/or its affiliates<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../for_each.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../for_each.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="for_each_segment.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
